package pacBioSimple;

import pacBiopackage.GetOpt;
import tools.kmer.KmerSet_binary;

public class MaskBadKmers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		GetOpt go = new GetOpt(args, "o:k:a:h:r:l:j");
		go.optErr = true;
		int ch = -1;
		
		// process options in command line arguments
		// Set default values
		boolean usagePrint = false;                 
		String filenamePacBio = "";   
		String filenameOutput="output.txt";
		String filenameKmerObject = "";
		boolean jelly=false;
		int kmer_count_limit =2000000000;
		int left_limit=0;
		while ((ch = go.getopt()) != GetOpt.optEOF) 
		{
		    if ((char)ch == 'h') {
		       usagePrint = true;
		   }
		    else if ((char)ch == 'a') {
		    	filenamePacBio = go.optArgGet();
		    }
		    else if((char)ch =='o')
		    {
		    	filenameOutput = go.optArgGet();
		    }
		    else if((char)ch =='k')
		    {
		    	filenameKmerObject=go.optArgGet();
		    }
		    else if((char)ch =='r')
		    {
		    	kmer_count_limit=Integer.valueOf(go.optArgGet());
		    }
		    else if((char)ch =='j')
		    {
		    	jelly=true;
		    }
		    else if((char)ch =='l')
		    {
		    	left_limit=Integer.valueOf(go.optArgGet());
		    }
		    else
		        System.exit(1);                     // undefined option
		}                                           // getopt() returns '?'
		
		if (usagePrint || filenameKmerObject.isEmpty() || filenamePacBio.isEmpty()) {
		    System.out.println("Usage: -a PacBio -k bad-Kmer -r kmer_count_limit_right -l kmer_count_limit_left -j[ -o outputFile -h]"); //NOI18N
		    System.exit(0);
		}
		
		// @TODO check if files exist
	
		System.out.println("------------------------");
		System.out.println("Command line parameter settings:");
		System.out.println("-a " + filenamePacBio); //NOI18N
		System.out.println("-o " + filenameOutput); //NOI18N
		System.out.println("-n " + kmer_count_limit); //NOI18N
		System.out.println("-l " + left_limit); //NOI18N
		System.out.println("-k " + filenameKmerObject); //NOI18N
		System.out.println("-j " + jelly); //NOI18N
		System.out.println("------------------------");
		
		
		//first we have to read the kmersFromthe file
		KmerSet_binary ks = null;
		ks=MyUtil.readKmers(filenameKmerObject, jelly, left_limit, kmer_count_limit, ks);
		SlideAndMaskPacBio mask = new SlideAndMaskPacBio(filenamePacBio, ks, filenameOutput);
		mask.doSlidingAndMasking();
		
	}

}
